<?php
// View for admin - articles
require_once WACT_ROOT . 'controller/controller.inc.php';
require_once WACT_ROOT . 'controller/form.inc.php';
require_once WACT_ROOT . 'view/view.inc.php';
require_once WACT_ROOT . 'view/formview.inc.php';

require_once APP_ROOT . 'view/common/layout.formview.php';
require_once APP_ROOT . 'view/common/layout.view.php';

require_once 'model/common/user.php';
require_once 'model/common/article.php';
require_once 'model/common/categories.php';
require_once 'model/common/date.php';
require_once 'model/common/form.php';


class FeedbacksListView extends LayoutFormView {

    function FeedbacksListView($TemplateFile) {
        parent :: LayoutFormView($TemplateFile);
    }

    function prepare(&$controller, &$request, &$responseModel) {
    	parent::prepare($controller, $request, $responseModel);
				        
		$this->Template->set('SITE_CSS',Site::getSiteTemplateCSS());
		$this->Template->set('SITE_BASE',Site::getSiteTemplateBase());
		$this->Template->set('SITE_TITLE',Site::getTitle());
 

        $pager =& $this->Template->getChild('pagenav');
        $pager2 =& $this->Template->getChild('pagenav2');
        $list =& SubmissionForm::getFeedbacksPagedList($pager,$request,$responseModel);
        $list->paginate($pager2);


        $list_updated=array();


        $list->reset();
        while ($list->next()) {

        	$dataspace = $list->export();
            $firstname = $list->get('firstname');
            $lastname = $list->get('lastname');
            $article_id = $list->get('article_id');
            $submission_id = $list->get('submission_id');
            $user_show = $firstname.' '.$lastname;
            $dataspace['user_show'] =  $user_show;

            $category1 = $list->get('category1');
            $category2 = $list->get('category2');

            $category_show = $category1.'-'.$category2;
            $dataspace['category_show'] =  $category_show;

            $premium = $list->get('premium');
            if ($premium) $dataspace['premium_show'] =  1;

            // print_r($dataspace);
            $list_updated[$submission_id] = $dataspace;
        }


        $list_source_updated =& new ArrayDataSet($list_updated);
        $this->Template->setChildDataSource('List', $list_source_updated);

        //populate sort combo
        $sortby =& $this->Template->getChild('sort');
        $sort_list = array('S.submission_id'=>'ID','F.title'=>'Headline','A.category_id, A.category2_id'=>'Category','S.user_id'=>'user','S.date'=>'Date Submitted' );
        $sortby->setChoices($sort_list);

        //populate recent combo
        $recent =& $this->Template->getChild('recent');
        $recent_list  =& Article::getResentList();
        $recent->setChoices($recent_list);

        //populate months
        $start_month =& $this->Template->getChild('start_month');
        $end_month =& $this->Template->getChild('end_month');
        $months_list =& SportDate::getMonthsList();
        $start_month->setChoices($months_list);
        $end_month->setChoices($months_list);

        //prepopulate start and end date
        $cur_month = (integer)date("m");
        $cur_year = (integer)date("Y");
        $cur_day = (integer)date("d");

        if ( $cur_month==1 ) {
        	$prev_month = 12;
        	$prev_year = $cur_year-1;
        }  else {
           $prev_month = $cur_month - 1;
           $prev_year = $cur_year;
        }

        if ( $cur_month==12 ) {
        	$next_month = 1;
        	$next_year = $cur_year+1;
        }  else {
           $next_month = $cur_month + 1;
           $next_year = $cur_year;
        }

        $start_day =& $this->Template->getChild('start_day');
        $day = $start_day->getValue();
        if (!$day) $start_day->setValue(1);

        $end_day =& $this->Template->getChild('end_day');
        $day = $end_day->getValue();
        if (!$day) $end_day->setValue($cur_day);

        //print $start_month->getValue();
        if ($start_month->getValue()<=0) $start_month->setSelection($prev_month);
        if ($end_month->getValue()<=0) {
        	//print $cur_month;
        	$end_month->setSelection($cur_month);
        }

        $start_year =& $this->Template->getChild('start_year');
        $year = $start_year->getValue();
        if (!$year) $start_year->setValue($prev_year);

        $end_year =& $this->Template->getChild('end_year');
        $year = $end_year->getValue();
        if (!$year) $end_year->setValue($cur_year);

        //populate categories
        $categories1 =& CategoriesModel::getSportCategories(false,false);
        //print_r($categories1);
        $categories2 =& CategoriesModel::getCommunityCategories(false,false);
        $category1 =& $this->Template->getChild('category1');
        $category2 =& $this->Template->getChild('category2');
        $category1->setChoices($categories1);
        $category2->setChoices($categories2);

        //populate authors
        $authors_list =& User::getAuthorsList();
        $author =& $this->Template->getChild('author');
        $author->setChoices($authors_list);

        //populate registered users - list of feedback users
        $users_list =& User::getUsersList();
        $user =& $this->Template->getChild('user_id');
        $user->setChoices($users_list);

        //populate feedback forms
        $forms_list =& FormModel::getFeedbackFormsForCombo();
        $form =& $this->Template->getChild('form_id');
        $form->setChoices($forms_list);

    }

}






?>